<?php
/**
 *
 *
 */
namespace Yz\modules\Admin;
use Yz_Array,
    Yz_Hash;
class Controller_Default
    extends \Yz_Controller_Abstract
{


    /**
     *
     */
    public function doGet( Yz_Array $args )
    {
        $this->checkValidUser();

        $path = '';
        if (0 === $args->count()) {
            // TODO fetch the default admin module from config
            $args->push("tasklist");
        }
        return false;
    }


    /**
     *  @return this
     */
    public function doPost( Yz_Array $args, Yz_Hash $post )
    {
        if (0 === $args->count()) {
            throw new \Yz_Access_Exception_Forbidden("Access via POST method denied");
        }
        return $this->doGet($args);
    }



    /** check if user is eligible for Admin area
     *  @return this
     *  @throw Yz_Access_Exception_Forbidden
     *  @throw Yz_Access_Exception_Unauthenticated
     */
    protected function checkValidUser()
    {
        debug();
        $user = \Yz_User_Default::getInstance();
        if ($user->isAdmin()) {
            return $this->enterAdmin();
        }
        if ($user->isAuthenticated()) {
            $ex = new \Yz_Access_Exception_Forbidden();
        } else {
            $ex = new \Yz_Access_Exception_Unauthenticated();
        }
        throw $ex->withArgs(array('area' => 'Admin'));
    }

}
